package com.dgh.school.controller;


import com.dgh.school.bean.Duty;
import com.dgh.school.common.R;
import com.dgh.school.service.DutyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DutyController {

    @Autowired
    private DutyService dutyService;

    @RequestMapping("/duty/dutys")
    public R selectByPage(int pageNum, int pageSize){
        try {
            return dutyService.selectByPage(pageNum,pageSize);
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/duty/delete")
    public R deleteById(int id){
        try {
            dutyService.deleteById(id);
            System.out.println(id);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/duty/add")
    public R add(Duty duty){
        try {
            dutyService.insertData(duty);
            System.out.println(duty);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/duty/modify")
    public R modify(Duty duty){
        try {
            dutyService.updateData(duty);
            System.out.println(duty);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/duty/dutyall")
    public R selectAllDutys(){
        try {

            return dutyService.selectAllDutys();
        } catch (Exception e) {
            return R.error();
        }
    }

}
